package com.woniuxy.mesboot.controller;

import com.woniuxy.mesboot.entity.MatOut;

import com.woniuxy.mesboot.service.MatOutService;
import com.woniuxy.mesboot.util.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("matout")
public class MatOutController {
    @Resource
    private MatOutService matOutService;

    @GetMapping
    public Result queryAll() {
        List<MatOut> i = matOutService.selectAll();
        return Result.ok().data("list", i);

    }

    @PostMapping
    public Result insert(@RequestBody MatOut matOut) {
        int insert = matOutService.insertSelective(matOut);
        if (insert > 0) {
            return Result.ok("添加成功");
        } else {
            return Result.error("添加失败");
        }
    }

    @DeleteMapping("{id}")
    public Result delete(@PathVariable Long id) {
        int i = matOutService.deleteByPrimaryKey(id);
        if (i > 0) {
            return Result.ok("删除成功");
        } else {
            return Result.error("删除失败");
        }
    }

    @GetMapping("{id}")
    public Result queryById(@PathVariable Long id) {
        MatOut matOut = matOutService.selectByPrimaryKey(id);
        return Result.ok().data("item", matOut);
    }

    @PutMapping
    public Result update(@RequestBody MatOut matOut) {
        int i = matOutService.updateByPrimaryKey(matOut);
        if (i > 0) {
            return Result.ok("修改成功");

        } else {
            return Result.error("修改失败");
        }
    }
}
